class Api::V1::NotificationsController < Api::V1::BaseController
  def index
    @notifications = @current_user.notifications.order("created_at DESC").page(params[:page]).per(params[:per])
  end

  def update
    @notification = Notification.find params[:id]
    if @notification.user_id == @current_user.id
      if @notification.update(state: :read)
        render json: { result: true, message: '已阅读.' }, status: :ok
      else
        render json: { result: false, message: '有错误.' }, status: :ok
      end
    else
      render json: { result: false, message: '无权操作.' }, status: :ok
    end
  end

  def destroy
    @notification = Notification.find params[:id]
    if @notification.user_id == @current_user.id
      if @notification.destroy
        render json: { result: true, message: '已删除.' }, status: :ok
      else
        render json: { result: false, message: '有错误.' }, status: :ok
      end
    else
      render json: { result: false, message: '无权操作.' }, status: :ok
    end
  end
  
  
end
